package com.codegeek.project.communicate;

import com.codegeek.project.slope.domain.SlopeDevice;
import com.codegeek.project.slope.domain.SlopeGlare;
import com.codegeek.project.slope.service.ISlopeDeviceService;
import com.codegeek.project.slope.service.ISlopeGlareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author wj
 * @ClassName
 * @Description
 * @date 2020-03-26
 */
@Component
public class SlopeGlareHandleService  {

    @Autowired
    private ISlopeDeviceService slopeDeviceService;

    @Autowired
    private ISlopeGlareService slopeGlareService;


    //设置设备上下线 0-离线  1-在线
    public  boolean setGlareState(String imei,int newState){
        SlopeGlare sg= slopeGlareService.selectValidSlopeGlareByImei(imei);
        if(sg!=null&&sg.getDevice()!=null){
            SlopeDevice sd=sg.getDevice();
            sd.setState(newState);
            slopeDeviceService.updateSlopeDevice(sd);
            return true;
        }
        return  false;
    }

    //设置报警器开关状态 on-开启  off-关闭
    public  void setGlareSwitchState(String imei,boolean on){
        SlopeGlare sg=slopeGlareService.selectValidSlopeGlareByImei(imei);
        if(sg!=null){
            sg.setReserve(on?"1":"0");
            slopeGlareService.updateSlopeGlare(sg);
        }
    }

}
